import { useEffect } from 'react';
import ReactDOM from 'react-dom';
import { Provider, useSelector } from 'react-redux';
import store from './store';
import "@arco-design/web-react/dist/css/arco.css";
import './App.scss'
import router from './router'
import './utils/rem'
import { useWebSocket } from '@/hooks/useWebSocket';
import Cookies from 'js-cookie';
import { LoadingProvider } from '@/components/common/mlsLoading/laodingText';

const App = () => {
  const user = useSelector(state => state.auth.user);
  const { connect } = useWebSocket();
  useEffect(() => {
    window.addEventListener('storage', (event) => {
      // 处理事件
      if (event.key === 'loginInfo') {
        // 执行退出操作
        location.href = '/'
      }
    });
    if (user?.userId&&Cookies.get('token')) {
      connect(user.userId,Cookies.get('token'));
    }
  }, [user]);
  return router;
};


document.body.setAttribute('theme-mode', 'dark');
document.body.setAttribute('arco-theme', 'dark');
ReactDOM.render(
  <Provider store={store}>
    <LoadingProvider>
      <App />
    </LoadingProvider>
  </Provider>,
  document.getElementById('root')
);

